Skip to content

Feature/stallguard autotune - #6

Merged
daniel-frenkel merged 3 commits into
mainfrom
feature/stallguard-autotune
Jul 24, 2026
Merged

daniel-frenkel merged 3 commits into
mainfrom
feature/stallguard-autotune

Conversation

@daniel-frenkel

Copy link
Copy Markdown
Member

No description provided.

Continuously cross-check StallGuard against the accelerometer and nudge SGTHRS so
the tune self-corrects between calibrations. New "StallGuard Auto-Tune" switch
(advanced group, default OFF) gates it; requires StallGuard + Vibration Stall
Detection both on.

Two directions, both small (+/-1 register step), clamped, logged, and counted via
a new "Auto-Tune Adjustments" diagnostic:
- RAISE (high confidence): when the vibration detector trips (its sustained-judder
  threshold = a real stall) but StallGuard did NOT fire this travel, StallGuard was
  too insensitive -> SGTHRS += step (ceiling 60).
- LOWER (conservative): a StallGuard trip is cross-checked in sg_autotune_eval. If
  peak vibration this travel stayed below half the Vibration Threshold AND the trip
  was mid-travel (not near an end stop), it is counted as a probable false trip.
  Only after THREE consecutive such quiet trips -> SGTHRS -= step (floor 2). A
  vibration-agreeing trip or a clean full travel (limit reached) resets the streak,
  so a single missed-judder stall can't desensitize StallGuard.

State: vib_run_peak + sg_fired_this_move reset at motion start, tracked in the
vibration interval / on_stall; sg_quiet_streak and a persisted sg_autotune_count.
A fresh Auto-Calibrate always overrides whatever auto-tune has drifted to.

Config valid; full compile OK. Default OFF so behaviour is unchanged until enabled.
…, raise cap

Add a "Speed" preset select (Motion Tuning) mapping Slow/Medium/Fast to
1200 / 2600 / 5500 steps/s, and demote the raw Speed slider to the advanced
group (mirrors the Ropener pattern). Raise stepper_max_speed 1200 -> 5500 so
Fast is reachable.

Values chosen from an accelerometer resonance sweep of this mechanism (external
measurement tool, not shipped): vibration is flat and quiet across the range
EXCEPT a violent drivetrain resonance at ~2900-3300 (worst 3000-3100, peak ~1 g).
All three presets avoid parking in that band; ramps cross it only transiently,
which measured harmless (clean position tracking). The motor holds torque with no
step loss all the way to 9000, but 6000+ free-run vibration exceeds the vib-stall
threshold, so the product cap sits at 5500 (Fast) to stay clear of false trips.

The select reads/writes global_speed (single source of truth, restored on boot);
changing speed auto-flags the StallGuard calibration stale (SG_RESULT is
speed-dependent). Verified on hardware: Slow->1200, Medium->2600, Fast->5500.
@daniel-frenkel
daniel-frenkel merged commit e42be0d into main Jul 24, 2026
@daniel-frenkel
daniel-frenkel deleted the feature/stallguard-autotune branch July 24, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant